//
//  LKMainViewController.swift
//  LKWeibo
//
//  Created by like on 16/8/9.
//  Copyright © 2016年 like. All rights reserved.
//

import UIKit

class LKMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabbar = LKTabBar()
        
        tabbar.LKDelegaer = self
       // self.tabBar = tabbar  tabbar 为只读的，无法这样赋值， 通过KVC 来赋值
        setValue(tabbar, forKey: "tabBar")
        
        //主页
        addviewController(LKHomeViewController(), tit: "主页", imageName: "tabbar_home")
        //消息
        addviewController(LKMessageViewController(), tit: "消息", imageName: "tabbar_message_center")
        //发现
        addviewController(LKDiscoverViewController(), tit: "发现", imageName: "tabbar_discover")
        //我们
        addviewController(LKProfileViewController(), tit: "我们", imageName: "tabbar_profile")
    }
    
//添加子控制器的方法
    func addviewController(vc:UIViewController,tit:String,imageName:String){
        vc.navigationItem.title = tit
        vc.tabBarItem.title = tit
        
        //单独对图片 文字进行渲染
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:appThemeColor], forState: UIControlState.Selected)
        
        vc.tabBarItem.image = UIImage(named: imageName)
        // AlwaysOriginal 图片渲染方式
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        self.addChildViewController(UINavigationController(rootViewController: vc))
    }
    
 
}

extension LKMainViewController:LKTabBarDelegate{
    func tabBarClick() {
        
        if !LKUserAccountViewModel.sharedTools.isLogin {
            printLog("请登录")
            return
        }
        printLog("点击了加号")
        let vc = LKComposeViewController()
        self.presentViewController(UINavigationController(rootViewController: vc), animated: true) {
        }

    }
}
